#include "globals.h"
#include <iostream>

int main()
{
	Modesto *modesto = new Modesto("config.xml");

	modesto->loadModules();

	std::vector<std::string> channels;
	channels.push_back("#ModestoTest");

	modesto->addConnection(ServerInfo("irc.zibings.net", "6667", "MasterChief", "", channels));

	if (modesto->connect())
	{
		modesto->startListening();
	}

	/**
	 * This loop is using a ridiculous amount of CPU.
	 *
	 * modesto->fetchQueue() is supposed to put the thread in a low CPU usage state.
	 * for some reason, it's not!
	 *
	 * There must be a better way to handle this problem ... other than using Sleep(seconds).
	 */
	while (modesto->isRunning())
	{
		Queue queue = modesto->fetchQueue();

		for (QueueIterator it = queue.begin(); it != queue.end(); ++it)
		{
			if (modesto->executeCommand(*it))
			{
				// We cannot erase a command while iterating through them!!!
				//queue.erase(it);
			}
		}
	}

	modesto->unloadModules();
	modesto->terminate();

	return 0;
}